public class Test {

    public static void main1(String[] args) {
        // 数字转字符串
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
        //String s4 = String.valueOf(new Student("Hanmeimei", 18));
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);


        // 字符串转数字
        int data1 = Integer.parseInt("1234");
        double data2 = Double.parseDouble("12.34");
        System.out.println(data1);
        System.out.println(data2);
    }

    public static void main2(String[] args) {
        String s1 = "hello";
        String s2 = "HELLO";
        // 小写转大写
        System.out.println(s1.toUpperCase());
        // 大写转小写
        System.out.println(s2.toLowerCase());
    }

    public static void main11(String[] args) {
        String s = "hello";

        // 字符串转数组
        char[] ch = s.toCharArray();
        for (int i = 0; i < ch.length; i++) {
        System.out.print(ch[i]);
        }

        // 数组转字符串
        String s2 = new String(ch);
        System.out.println(s2);
    }


    public static void main22(String[] args) {
        String s = String.format("%d-%d-%d", 2019, 9,14);
        System.out.println(s);

    }

    public static void main21(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.replaceAll("l", "_"));
        System.out.println(str.replaceFirst("l", "_"));

    }

    public static void main3(String[] args) {

        // 实现字符串的拆分处理
        String str = "hello world hello sir" ;
        String[] result1 = str.split(" ") ;  // 按照空格拆分
        for(String s: result1) {
        System.out.println(s);
        }

        // 字符串的部分拆分
        String[] result2 = str.split(" ",2) ;
        for(String s: result2) {
        System.out.println(s);
        }

        String s = "192.168.1.1" ;
        String[] result = str.split("\\.") ;
        for(String p: result) {
        System.out.println(p);
        }

        String p = "name=zhangsan&age=18" ;
        String[] t = p.split("=|&");
        for(String x : t) {
            System.out.println(x);
        }
    }

    public static void main12(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.substring(5));
        System.out.println(str.substring(0, 5));
    }

    public static void main(String[] args) {
        // trim()方法的使用
        String str = "  hello world  " ;
        System.out.println("["+str+"]");         // [  hello world  ]
        System.out.println("["+str.trim()+"]");  // [hello world]

        // 大小写转换
        String s = "  hello%$$%@#$%world 哈哈哈 " ;
        System.out.println(s.toUpperCase());    //  HELLO%$$%@#$%WORLD 哈哈哈
        System.out.println(s.toLowerCase());    //  hello%$$%@#$%world 哈哈哈
    }
}
